package com.ruoyi.project.pms.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.db.pms.domain.PmsIssue;
import com.ruoyi.db.pms.domain.query.PmsIssueQueryVo;
import com.ruoyi.project.pms.service.PmsIssueService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 常见问题Controller
 *
 * @author ruoyi
 * @date 2020-04-23
 */
@Api(tags="pms管理：常见问题管理")
@RestController
@RequestMapping("/pms/issue")
public class PmsIssueController extends BaseController
{
    @Autowired
    private PmsIssueService pmsIssueService;

    @ApiOperation("查询常见问题列表")
    @PreAuthorize("@ss.hasPermi('pms:issue:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmsIssueQueryVo pmsIssueQueryVo)
    {
        startPage();
        List<PmsIssue> list = pmsIssueService.selectPmsIssueList(pmsIssueQueryVo);
        return getDataTable(list);
    }

    @ApiOperation("导出常见问题列表")
    @Log(title = "常见问题", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('pms:issue:export')")
    @GetMapping("/export")
    public AjaxResult export(PmsIssueQueryVo pmsIssueQueryVo)
    {
        List<PmsIssue> list = pmsIssueService.selectPmsIssueList(pmsIssueQueryVo);
        ExcelUtil<PmsIssue> util = new ExcelUtil<PmsIssue>(PmsIssue.class);
        return util.exportExcel(list, "issue");
    }

    @ApiOperation("获取常见问题详细信息")
    @Log(title = "常见问题", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('pms:issue:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pmsIssueService.selectPmsIssueById(id));
    }

    @ApiOperation("新增常见问题")
    @Log(title = "常见问题", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('pms:issue:add')")
    @PostMapping
    public AjaxResult add(@RequestBody PmsIssue pmsIssue)
    {
        return toAjax(pmsIssueService.insertPmsIssue(pmsIssue));
    }

    @ApiOperation("修改常见问题")
    @Log(title = "常见问题", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('pms:issue:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody PmsIssue pmsIssue)
    {
        return toAjax(pmsIssueService.updatePmsIssue(pmsIssue));
    }

    @ApiOperation("删除常见问题")
    @Log(title = "常见问题", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('pms:issue:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pmsIssueService.deletePmsIssueByIds(ids));
    }
}
